<template>
  <el-dialog
    v-model="visible"
    :modal="false"
    title="退款审核"
    :close-on-click-modal="false"
  >
    <el-form
      ref="dataFormRef"
      :model="dataForm"
      :rules="dataRule"
      label-width="80px"
      @keyup.enter="onSubmit()"
    >
      <el-form-item label="退款">
        <el-radio-group v-model="dataForm.refundSts" >
          <el-radio :label="2"> 同意 </el-radio>
          <el-radio :label="3"> 拒绝 </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        label="备注"
        prop="dvyFlowId"
      >
        <el-input
          v-model="dataForm.sellerMsg"
          controls-position="right"
          :min="0"
          label="备注"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button
          type="primary"
          @click="onSubmit()"
        >确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ElMessage } from 'element-plus'
const emit = defineEmits(['refreshDataList'])
const id=defineProps({
  orderId:{
    type: String,
    default: "",

  }
})
// eslint-disable-next-line no-unused-vars
const validDvyFlowId = (rule, value, callback) => {
  if (!value.trim()) {
    callback(new Error('不能为空'))
  } else {
    callback()
  }
}
const dataRule = {
  buyerMsg: [
    { required: true, message: '不能为空', trigger: 'blur' },
    { validator: validDvyFlowId, trigger: 'blur' }
  ]
}

const visible = ref(false)
const dataForm = reactive({
  dvyId: '',
  dvyFlowId: 0,
  dvyNames: [],
  orderNumber: 0
})

const init = (orderNumber, dvyId, dvyFlowId) => {
  visible.value = true
  dataForm.orderNumber = orderNumber || ''
  dataForm.dvyId = dvyId || ''
  dataForm.dvyFlowId = dvyFlowId || ''
  http({
    url: http.adornUrl('/admin/delivery/list'),
    method: 'get',
    params: http.adornParams()
  }).then(({ data }) => {
    dataForm.dvyNames = data
  })
}
defineExpose({ init })

const dataFormRef = ref(null)
/**
 * 表单提交
 */
const onSubmit = () => {
  dataFormRef.value?.validate((valid) => {
    if (valid) {
     
      http({
        url: http.adornUrl('/p/orderRefund/auditOrder'),
        method: 'post',
        data: http.adornData({
          refundSts: dataForm.refundSts,
          orderId: dataForm.orderNumber.orderId,
          sellerMsg: dataForm.sellerMsg,
          refundId:dataForm.orderNumber.refundId,
          userId:dataForm.orderNumber.userId,
          refundAmount:dataForm.orderNumber.refundAmount
        })
      })
        .then(() => {
          ElMessage({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              visible.value = false
              emit('refreshDataList')
            }
          })
        })
    }
  })
}

</script>
